#include <string>
#include "DateUnitTest.h"
#include "assertions.h"
#include "Date.h"

void testFullConstructor()
{
	Date date(2010, Date::Feb, 23, 14, 23, 34);
	assertEquals<int>( 2010, date.getYear() );
	assertEquals<int>( Date::Feb, date.getMonth() );
	assertEquals<int>( 23, date.getDay() );
	assertEquals<int>( 14, date.getHour() );
	assertEquals<int>( 23, date.getMinute() );
	assertEquals<int>( 34, date.getSecond() );
}

void testConstructorWithIncorrectArguments()
{
	Date date(2010, Date::Feb, 30, 22, 59, 72);
	assertEquals<int>( 2010, date.getYear() );
	assertEquals<int>( Date::Mar, date.getMonth() );
	assertEquals<int>( 2, date.getDay() );
	assertEquals<int>( 23, date.getHour() );
	assertEquals<int>( 0, date.getMinute() );
	assertEquals<int>( 12, date.getSecond() );
}

void testAddYear()
{
	Date date(2010, Date::Jan, 31, 1, 59, 59);
	date = date.addYear(1);
	assertEquals<int>( 2011, date.getYear() );
	assertEquals<int>( Date::Jan, date.getMonth() );
	assertEquals<int>( 31, date.getDay() );
	assertEquals<int>( 1, date.getHour() );
	assertEquals<int>( 59, date.getMinute() );
	assertEquals<int>( 59, date.getSecond() );
}

void testAddMonth()
{
	Date date(2010, Date::Jan, 31, 1, 59, 59);
	date = date.addMonth(1);
	assertEquals<int>( 2010, date.getYear() );
	assertEquals<int>( Date::Mar, date.getMonth() );
	assertEquals<int>( 3, date.getDay() );
	assertEquals<int>( 1, date.getHour() );
	assertEquals<int>( 59, date.getMinute() );
	assertEquals<int>( 59, date.getSecond() );
}


void testAddDay()
{
	Date date(2010, Date::Feb, 28, 1, 59, 59);
	date = date.addDay(1);
	assertEquals<int>( 2010, date.getYear() );
	assertEquals<int>( Date::Mar, date.getMonth() );
	assertEquals<int>( 1, date.getDay() );
	assertEquals<int>( 1, date.getHour() );
	assertEquals<int>( 59, date.getMinute() );
	assertEquals<int>( 59, date.getSecond() );
}

void testAddHour()
{
	Date date(2010, Date::Feb, 23, 23, 59, 59);
	date = date.addHour(2);
	assertEquals<int>( 2010, date.getYear() );
	assertEquals<int>( Date::Feb, date.getMonth() );
	assertEquals<int>( 24, date.getDay() );
	assertEquals<int>( 1, date.getHour() );
	assertEquals<int>( 59, date.getMinute() );
	assertEquals<int>( 59, date.getSecond() );
}

void testAddMinute()
{
	Date date(2010, Date::Feb, 23, 14, 59, 59);
	date = date.addMinute(2);
	assertEquals<int>( 2010, date.getYear() );
	assertEquals<int>( Date::Feb, date.getMonth() );
	assertEquals<int>( 23, date.getDay() );
	assertEquals<int>( 15, date.getHour() );
	assertEquals<int>( 1, date.getMinute() );
	assertEquals<int>( 59, date.getSecond() );
}

void testAddSecond()
{
	Date date(2010, Date::Feb, 23, 14, 23, 59);
	date = date.addSecond(2);
	assertEquals<int>( 2010, date.getYear() );
	assertEquals<int>( Date::Feb, date.getMonth() );
	assertEquals<int>( 23, date.getDay() );
	assertEquals<int>( 14, date.getHour() );
	assertEquals<int>( 24, date.getMinute() );
	assertEquals<int>( 1, date.getSecond() );
}

void testFormat()
{
	Date date(2011, Date::Mar, 12, 14, 23, 43);
	std::string formatedDate = date.formatDate("YYYY-MMM-DD hh::mm::ss");
	assertEquals<std::string>("2011-Mar-12 14::23::43", formatedDate);
}

void dateTestSuite()
{
	testFullConstructor();
	testConstructorWithIncorrectArguments();
	testAddYear();
	testAddMonth();
	testAddDay();
	testAddHour();
	testAddMinute();
	testAddSecond();
	testFormat();
}